home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / ControlPanelLock / OpenDeskAcc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-05  |  4.0 KB  |  259 lines  |  [TEXT/KAHL]

  1. #include "CPanel Lock.h"
  2.  
  3. pascal void HiliteDefaultButton(DialogPtr theDPtr,int whichItem);
  4. int GetInput(char *thePrompt,char *theText,int defaultItem);
  5. int CommandKey(void);
  6. int OptionKey(void);
  7. int Pstrcmp(char *s1, char *s2);
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. pascal int main(char *theDAName)
  15. {
  16. int                i,j;
  17. char            permit;
  18. char            *cPanelNameS6,*cPanelNameS7;
  19.  
  20.     asm
  21.     {
  22.             lea.l    @cpnmS6,a1
  23.             lea.l    cPanelNameS6,a0
  24.             move.l    a1,(a0)
  25.             
  26.             lea.l    @cpnmS7,a1
  27.             lea.l    cPanelNameS7,a0
  28.             move.l    a1,(a0)
  29.             
  30.             bra.s    @skip
  31.             
  32.             dc.b    magicWord
  33. oldTrap:    dc.b    0,0,0,0
  34. cpnmS6:        dc.b    CPANELNAMES6,0
  35. cpnmS7:        dc.b    CPANELNAMES7,0
  36.             dc.b    0
  37.  
  38. skip:        nop
  39.     }
  40.     
  41.     DebugStr("\pCalling Elvis");
  42.     
  43.     permit = TRUE;
  44.     
  45.     if (theDAName[0])
  46.     {
  47.         for (j=0,i=theDAName[0];i > 0 && theDAName[j] == cPanelNameS6[j];i--,j++);
  48.         
  49.         if (i <= 0)
  50.         {
  51.             if (!OptionKey() || !CommandKey() || !CheckPassword())
  52.                 permit = FALSE;
  53.         }
  54.         
  55.         if (permit)
  56.         {
  57.             for (j=0,i=theDAName[0];i > 0 && theDAName[j] == cPanelNameS7[j];i--,j++);
  58.             
  59.             if (i <= 0)
  60.             {
  61.                 if (!OptionKey() || !CommandKey() || !CheckPassword())
  62.                     permit = FALSE;
  63.             }
  64.         }
  65.     }
  66.     
  67.     if (!permit)
  68.     {
  69.         SysBeep(1);
  70.         return;
  71.     }
  72.     
  73.     asm 
  74.     {
  75.             move.l    @oldTrap, a0
  76.             unlk    a6
  77.             jmp        (a0)
  78.     }
  79. }
  80.  
  81.  
  82.  
  83.  
  84. int OptionKey(void)
  85. {
  86. char    theKeyMap[16];
  87.  
  88.     GetKeys(theKeyMap);
  89.     
  90.     if (theKeyMap[7] & 0x04)
  91.         return(TRUE);
  92.     else
  93.         return(FALSE);
  94. }
  95.  
  96.  
  97.  
  98.  
  99. int CommandKey(void)
  100. {
  101. char    theKeyMap[16];
  102.  
  103.     GetKeys(theKeyMap);
  104.     
  105.     if (theKeyMap[6] & 0x80)
  106.         return(TRUE);
  107.     else
  108.         return(FALSE);
  109. }
  110.  
  111.  
  112.  
  113.  
  114. pascal void HiliteDefaultButton(DialogPtr theDPtr,int whichItem)
  115. {
  116. int            type;
  117. Handle        theItem;
  118. Rect        theRect;
  119.  
  120.     GetDItem(theDPtr, ((DialogPeek) theDPtr)->aDefItem, &type, &theItem, &theRect);
  121.     PenNormal();
  122.     PenSize(3,3);
  123.     InsetRect(&theRect,-4,-4);
  124.     FrameRoundRect(&theRect,16,16);
  125.     PenSize(1,1);
  126. }
  127.  
  128.  
  129. int Pstrcmp(char *s1, char *s2)
  130. {
  131. int        i;
  132.  
  133.     i = *s1 + 1;
  134.     
  135.     while (i > 0 && *s1 == *s2)
  136.     {
  137.         s1++; 
  138.         s2++;
  139.         i--;
  140.     }
  141.     
  142.     if (i <= 0)
  143.         return(EQSTR);
  144.     else
  145.         return(!EQSTR);
  146. }
  147.  
  148.  
  149.  
  150. int CheckPassword()
  151. {
  152. DialogPtr        theDPtr,tempDPtr;
  153. int                itemHit, type, returnCode,i;
  154. int                oldResFRefNum,myResFRefNum;
  155. Handle            theItem,masterPassWord;
  156. Rect            tempRect;
  157. GrafPtr            oldPort;
  158. char            userPassWord[256];
  159. EventRecord        theEvent;
  160.  
  161.     oldResFRefNum = CurResFile();
  162.     
  163.     if ((myResFRefNum = OpenResFile(myResFileName)) == -1)
  164.     {
  165.         SysBeep(1);
  166.         return(FALSE);
  167.     }
  168.     
  169.     UseResFile(myResFRefNum);
  170.     
  171.     GetPort(&oldPort);
  172.  
  173.     InitCursor();
  174.     
  175.     theDPtr = GetNewDialog(PASSWDDLOG, 0L,(WindowPtr) -1L);
  176.     SetPort(theDPtr);
  177.     
  178.     /*CenterWindow(theDPtr);*/
  179.     ShowWindow(theDPtr);
  180.     
  181.     ((DialogPeek) theDPtr)->aDefItem = 1;
  182.     
  183.     GetDItem(theDPtr, 5, &type, &theItem, &tempRect);
  184.     SetDItem(theDPtr, 5, type, HiliteDefaultButton, &tempRect);
  185.     
  186.     i = 1;
  187.     userPassWord[0] = 0;
  188.     
  189.     do 
  190.     {
  191.         itemHit = 0;
  192.         
  193.         while (!GetNextEvent(everyEvent,&theEvent))
  194.         {
  195.             SystemTask();
  196.         
  197.             if (((DialogPeek) theDPtr)->editField>=0 && ((DialogPeek) theDPtr)->textH)
  198.                 TEIdle(((DialogPeek) theDPtr)->textH);
  199.         }
  200.         
  201.         if (theEvent.what==keyDown || theEvent.what==autoKey)
  202.         {
  203.             if ((theEvent.message & charCodeMask)=='\r' || (theEvent.message & charCodeMask)==0x03)
  204.                 itemHit = ((DialogPeek) theDPtr)->aDefItem;
  205.             
  206.             else if (i < 255)
  207.             {
  208.                 userPassWord[i++] = theEvent.message & charCodeMask;
  209.                 userPassWord[0] += 1;
  210.                 theEvent.message &= ~charCodeMask;
  211.                 theEvent.message |= '•';
  212.                 
  213.                 tempDPtr = 0L;
  214.                 itemHit = 0;
  215.                 
  216.                 DialogSelect(&theEvent,&tempDPtr,&itemHit);
  217.             }
  218.             
  219.             else
  220.                 SysBeep(1);
  221.         }
  222.         
  223.         else
  224.         {
  225.             tempDPtr = (DialogPtr) 0L;
  226.                 
  227.             if (!IsDialogEvent(&theEvent) || !DialogSelect(&theEvent,&tempDPtr,&itemHit) || tempDPtr!=theDPtr)
  228.                 itemHit = 0;
  229.         }
  230.         
  231.     } while (itemHit!=1 && itemHit!=2);
  232.     
  233.     
  234.     GetDItem(theDPtr, 4, &type, &theItem, &tempRect);
  235.     
  236.     if (itemHit==1)
  237.     {
  238.         masterPassWord = GetResource('STR ',PASSWORDSTR);
  239.         
  240.         if (masterPassWord == nil || Pstrcmp(userPassWord,(char *) *masterPassWord)!=EQSTR)
  241.             returnCode = FALSE;
  242.         
  243.         else
  244.             returnCode = TRUE;
  245.         
  246.         ReleaseResource(masterPassWord);
  247.     }
  248.     else
  249.         returnCode = FALSE;
  250.     
  251.     DisposDialog(theDPtr);
  252.     SetPort(oldPort);
  253.     
  254.     CloseResFile(myResFRefNum);
  255.     UseResFile(oldResFRefNum);
  256.     
  257.     return(returnCode);
  258. }
  259.